<template>
  <div>
    <van-datetime-picker
      v-model="currentDate"
      type="date"
      title="选择年月日"
      :min-date="minDate"
      :max-date="maxDate"
      @cancel="$emit('close-popup')"
      @confirm="onConfirm"
    />
  </div>
</template>

<script>
import { absoluteFormatDate } from '@/filters'
import { setUserProfile } from '@/api/user.js'
export default {
  data () {
    return {
      currentDate: new Date(this.value),
      minDate: new Date('1900-01-01'),
      maxDate: new Date()
    }
  },

  props: {
    value: {
      type: String,
      required: true
    }
  },

  created () {

  },

  methods: {
    async onConfirm (value) {
      // console.log(value)
      const date = absoluteFormatDate(value, 'YYYY-MM-DD')
      try {
        await setUserProfile({
          birthday: date
        })
        this.$toast('修改成功')
        this.$emit('close-popup')
        this.$emit('input', date)
      } catch (err) {
        this.$toast('修改失败')
      }
    }
  }
}
</script>

<style scoped lang='less'>

</style>
